package health_system.health_system.dto;

import health_system.health_system.entity.MomentShare;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.time.LocalDateTime;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class MomentShareDTO {
    private Long id;
    private Long userId;
    private String username;
    private String userAvatarUrl;
    private Long originalMomentId;
    private String originalMomentContent;
    private Long originalMomentUserId;
    private String originalMomentUsername;
    private String additionalComment;
    private Long sharedAsMomentId;
    private LocalDateTime createdAt;
    private LocalDateTime updatedAt;
    
    public static MomentShareDTO fromEntity(MomentShare share) {
        if (share == null) {
            return null;
        }
        
        MomentShareDTO dto = new MomentShareDTO();
        dto.setId(share.getId());
        
        if (share.getUser() != null) {
            dto.setUserId(share.getUser().getId());
            dto.setUsername(share.getUser().getUsername());
            dto.setUserAvatarUrl(share.getUser().getAvatarUrl());
        }
        
        if (share.getOriginalMoment() != null) {
            dto.setOriginalMomentId(share.getOriginalMoment().getId());
            dto.setOriginalMomentContent(share.getOriginalMoment().getContent());
            
            if (share.getOriginalMoment().getUser() != null) {
                dto.setOriginalMomentUserId(share.getOriginalMoment().getUser().getId());
                dto.setOriginalMomentUsername(share.getOriginalMoment().getUser().getUsername());
            }
        }
        
        dto.setAdditionalComment(share.getAdditionalComment());
        
        if (share.getSharedAsMoment() != null) {
            dto.setSharedAsMomentId(share.getSharedAsMoment().getId());
        }
        
        dto.setCreatedAt(share.getCreatedAt());
        dto.setUpdatedAt(share.getUpdatedAt());
        
        return dto;
    }
} 